import api from "@/api";
import { crypto } from "@/utils/tool";
const url: string = import.meta.env.DEV
	? "/public/static/SMS_verify.txt"
	: "/static/SMS_verify.txt";
const useSmsCode = async (query: { mobile: string; time: number }) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${url}?_t=${new Date().getTime()}`,
			type: "text",
			isOther: true,
			success: async ({ data }) => {
				const res = await api.auth.sendSms.get({
					mobile: query.mobile,
					time: query.time,
					sign: crypto
						.MD5(
							uni.$u.queryParams(
								Object.assign(query, { key: data }),
								false
							)
						)
						.toLocaleUpperCase(),
				});
				resolve(res);
			},
			fail: (err) => {
				reject(err);
			},
		});
	});
};
export { useSmsCode };
export default useSmsCode;
